
#include "HelloWorldScene.h"
#include "AppMacros.h"
#include "../proj.win32/DelayTest.h"
USING_NS_CC;


CCScene* HelloWorld::scene()
{
	CCScene *scene = CCScene::create();
	HelloWorld *layer = HelloWorld::create();
	scene->addChild(layer);
	return scene;
}

HelloWorld::HelloWorld()
	:_arrvatcan(NULL)
	,_arrchim(NULL)
	,_arrquai(NULL)
	,_arrnhanvat(NULL)
	,_arrtuongtrai(NULL)
	,_arrtuongphai(NULL)
	,_arrnvtieutrai(NULL)
	,_arrnvtieuphai(NULL)
	,_arrdaytrai(NULL)
	,_arrdayphai(NULL)
{
	CCDirector::sharedDirector()->setDisplayStats(true);
}   

HelloWorld::~HelloWorld()
{
	if (_arrvatcan)
	{
		_arrvatcan->release();
		_arrvatcan = NULL;
	}
	if (_arrquai)
	{
		_arrquai->release();
		_arrquai = NULL;
		
	}
	if (_arrchim)
	{
		_arrchim->release();
		_arrchim = NULL;

	}
	if (_arrnhanvat)
	{
		_arrnhanvat->release();
		_arrnhanvat = NULL;

	}
	if (_arrdaytrai)
	{
		_arrdaytrai->release();
		_arrdaytrai = NULL;

	}
	
	if (_arrdayphai)
	{
		_arrdayphai->release();
		_arrdayphai = NULL;

	}
	if (_arrtuongtrai)
	{
		_arrtuongtrai->release();
		_arrtuongtrai = NULL;

	}
	if (_arrtuongphai)
	{
		_arrtuongphai->release();
		_arrtuongphai = NULL;

	}
	if (_arrnvtieutrai)
	{
		_arrnvtieutrai->release();
		_arrnvtieutrai = NULL;

	}
	if (_arrnvtieuphai)
	{
		_arrnvtieuphai->release();
		_arrnvtieuphai = NULL;

	}
}

bool HelloWorld::init()
{
	if ( !CCLayerColor::initWithColor(ccc4(255,255,255,255)) )
	{
		return false;
	}
	s = CCDirector::sharedDirector()->getWinSize();
	
	nen = CCSprite::create("main.jpg");
	nen -> setPosition(ccp(s.width/2, s.height/2));
	this -> addChild(nen,1);
	CCScaleTo* pcale = CCScaleTo::create(0,2.7,3.2);
	nen -> runAction(pcale);

	CCMenuItemImage* play = CCMenuItemImage::create("play_button.png",0,
													this, menu_selector(HelloWorld::stargame));
		play->setPosition(ccp(50,220));
		CCMenu* pMenu = CCMenu::create(play, NULL);
		pMenu->setPosition(CCPointZero);
		nen ->addChild(pMenu,2);
		CCScaleTo *cale = CCScaleTo::create(0,1,1);
		play -> runAction(cale);
		

		/*CCMenuItemImage* pquit = CCMenuItemImage::create("quit.jpg",0,
												this, menu_selector(HelloWorld::menuCloseCallback));
		pquit->setPosition(ccp(origin.x + visibleSize.width/2, origin.y + visibleSize.height/2));
		pMenu1 = CCMenu::create(pquit, NULL);
		pMenu1->setPosition(CCPointZero);
		this->addChild(pMenu1, 1);
		CCScaleTo *cale1 = CCScaleTo::create(0,0.4);
		pquit -> runAction(cale1);*/

	
		
	return true;
}

void HelloWorld::stargame(CCObject* pSender)
{
	s = CCDirector::sharedDirector()->getWinSize();
	this -> removeChild(nen);
	_arrnhanvat = new CCArray;
	_arrvatcan = new CCArray;
	_arrchim = new CCArray;
	_arrquai = new CCArray;
	_arrtuongtrai = new CCArray;
	_arrtuongphai = new CCArray;
	_arrdaytrai = new CCArray;
	_arrdayphai = new CCArray;
	_arrnvtieuphai = new CCArray;
	_arrnvtieutrai = new CCArray;
	rgtryhujyt
	
	for(int i = 0; i <= 25; i++)
	{
		CCSprite *tuongphai = CCSprite::create("wall.png");
		tuongphai -> setFlipX(1);
		tuongphai -> setAnchorPoint(ccp(0,0));
		tuongphai -> setPosition(ccp(s.width - tuongphai -> getContentSize().width ,i*tuongphai -> getContentSize().height ));
		this -> addChild(tuongphai);
		_arrtuongphai->addObject(tuongphai);
}
	for(int i = 0; i <= 25; i++)
	{
		CCSprite *tuongtrai = CCSprite::create("wall.png");
		tuongtrai -> setAnchorPoint(ccp(0,0));
		tuongtrai -> setPosition(ccp(0, i*tuongtrai -> getContentSize().height));
		this -> addChild(tuongtrai);
		_arrtuongtrai -> addObject(tuongtrai);
	}
	

	CCSprite* nen = CCSprite::create("background.jpg");
	nen -> setPosition(ccp(s.width/2, s.height/2));
	this -> addChild(nen);
	CCScaleTo* pcale = CCScaleTo::create(0,2.5,3.3);
	nen -> runAction(pcale);
	
	CCSprite* sprstargame = CCSprite::create("foreground.png");
	sprstargame -> setPosition(ccp(s.width/2, sprstargame -> getContentSize().height/2));
	CCScaleTo* scalesprstargame = CCScaleTo::create(0, 3,1.5);
	sprstargame -> runAction(scalesprstargame);
	this -> addChild(sprstargame, 2);
	CCActionInterval* acsprstargame = CCMoveTo::create(1.6, ccp(s.width/2, 0 - sprstargame -> getContentSize().height));
	sprstargame -> runAction(acsprstargame);

	CCMenuItemImage *pCloseItem = CCMenuItemImage::create(
                                        "pause.png", "",this,menu_selector(HelloWorld::gamepause));
	CCScaleTo* scale = CCScaleTo::create(0, 2, 2);
	pCloseItem -> runAction(scale);
	pCloseItem -> setPosition(ccp(s.width - 28,28));
	CCMenu* pMenu = CCMenu::create(pCloseItem, NULL);
		pMenu->setPosition(CCPointZero);
		this->addChild(pMenu, 1);

	nhanvat = CCSprite::create("Climbing_0000.png");
	animnhanvat = CCAnimation::create();
	animnhanvat -> addSpriteFrameWithFileName("Climbing_0000.png");
	animnhanvat -> addSpriteFrameWithFileName("Climbing_0001.png");
	animnhanvat -> addSpriteFrameWithFileName("Climbing_0002.png");
	animnhanvat -> addSpriteFrameWithFileName("Climbing_0003.png");
	animnhanvat -> addSpriteFrameWithFileName("Climbing_0004.png");
	animnhanvat -> addSpriteFrameWithFileName("Climbing_0005.png");
	animnhanvat -> addSpriteFrameWithFileName("Climbing_0006.png");
	animnhanvat -> addSpriteFrameWithFileName("Climbing_0007.png");
	animnhanvat -> addSpriteFrameWithFileName("Climbing_0008.png");
	animnhanvat -> addSpriteFrameWithFileName("Climbing_0009.png");
	animnhanvat -> addSpriteFrameWithFileName("Climbing_0010.png");
	animnhanvat -> addSpriteFrameWithFileName("Climbing_0011.png");
	animnhanvat -> addSpriteFrameWithFileName("Climbing_0012.png");
	animnhanvat -> addSpriteFrameWithFileName("Climbing_0013.png");
	animnhanvat -> addSpriteFrameWithFileName("Climbing_0014.png");
	animnhanvat -> addSpriteFrameWithFileName("Climbing_0015.png");
	animnhanvat -> addSpriteFrameWithFileName("Climbing_0016.png");
	animnhanvat -> addSpriteFrameWithFileName("Climbing_0017.png");
	animnhanvat -> addSpriteFrameWithFileName("Climbing_0018.png");
	animnhanvat->setLoops(-1);
	animnhanvat->setDelayPerUnit(0.07f);

	nhanvat = CCSprite::create("flight_0000.png");
	animnhanvat1 = CCAnimation::create();
	animnhanvat1 -> addSpriteFrameWithFileName("flight_0000.png");
	animnhanvat1 -> addSpriteFrameWithFileName("flight_0001.png");
	animnhanvat1 -> addSpriteFrameWithFileName("flight_0002.png");
	animnhanvat1 -> addSpriteFrameWithFileName("flight_0003.png");
	animnhanvat1 -> addSpriteFrameWithFileName("flight_0004.png");
	animnhanvat1 -> addSpriteFrameWithFileName("flight_0005.png");
	animnhanvat1 -> addSpriteFrameWithFileName("flight_0006.png");
	animnhanvat1 -> addSpriteFrameWithFileName("flight_0007.png");
	animnhanvat1 -> addSpriteFrameWithFileName("flight_0008.png");
	animnhanvat1 -> addSpriteFrameWithFileName("flight_0009.png");
	animnhanvat1->setLoops(-1);
	animnhanvat1->setDelayPerUnit(0.07f);

	nhanvat = CCSprite::create("Bird_0000.png");
	animnhanvat2 = CCAnimation::create();
	animnhanvat2 -> addSpriteFrameWithFileName("Bird_0000.png");
	animnhanvat2 -> addSpriteFrameWithFileName("Bird_0001.png");
	animnhanvat2 -> addSpriteFrameWithFileName("Bird_0002.png");
	animnhanvat2 -> addSpriteFrameWithFileName("Bird_0003.png");
	animnhanvat2 -> addSpriteFrameWithFileName("Bird_0004.png");
	animnhanvat2 -> addSpriteFrameWithFileName("Bird_0005.png");
	animnhanvat2 -> addSpriteFrameWithFileName("Bird_0006.png");
	animnhanvat2 -> addSpriteFrameWithFileName("Bird_0007.png");
	animnhanvat2 -> addSpriteFrameWithFileName("Bird_0008.png");
	animnhanvat2 -> addSpriteFrameWithFileName("Bird_0009.png");
	animnhanvat2 -> addSpriteFrameWithFileName("Bird_0010.png");
	animnhanvat2 -> addSpriteFrameWithFileName("Bird_0011.png");
	animnhanvat2 -> addSpriteFrameWithFileName("Bird_0012.png");
	animnhanvat2 -> addSpriteFrameWithFileName("Bird_0013.png");
	animnhanvat2 -> addSpriteFrameWithFileName("Bird_0014.png");
	animnhanvat2->setLoops(-1);
	animnhanvat2->setDelayPerUnit(0.07f);

	nhanvat = CCSprite::create("Squirel_0000.png");
	animnhanvat3 = CCAnimation::create();
	animnhanvat3 -> addSpriteFrameWithFileName("Squirel_0000.png");
	animnhanvat3 -> addSpriteFrameWithFileName("Squirel_0001.png");
	animnhanvat3 -> addSpriteFrameWithFileName("Squirel_0002.png");
	animnhanvat3 -> addSpriteFrameWithFileName("Squirel_0003.png");
	animnhanvat3 -> addSpriteFrameWithFileName("Squirel_0004.png");
	animnhanvat3 -> addSpriteFrameWithFileName("Squirel_0005.png");
	animnhanvat3 -> addSpriteFrameWithFileName("Squirel_0006.png");
	animnhanvat3 -> addSpriteFrameWithFileName("Squirel_0007.png");
	animnhanvat3 -> addSpriteFrameWithFileName("Squirel_0008.png");
	animnhanvat3 -> addSpriteFrameWithFileName("Squirel_0009.png");
	animnhanvat3 -> addSpriteFrameWithFileName("Squirel_0010.png");
	animnhanvat3 -> addSpriteFrameWithFileName("Squirel_0011.png");
	animnhanvat3 -> addSpriteFrameWithFileName("Squirel_0012.png");
	animnhanvat3 -> addSpriteFrameWithFileName("Squirel_0013.png");
	animnhanvat3 -> addSpriteFrameWithFileName("Squirel_0014.png");
	animnhanvat3->setLoops(-1);
	animnhanvat3->setDelayPerUnit(0.07f);

	nhanvat = CCSprite::create("Falling_000.png");
	animnhanvat4 = CCAnimation::create();
	animnhanvat4 -> addSpriteFrameWithFileName("Falling_000.png");
	animnhanvat4 -> addSpriteFrameWithFileName("Falling_001.png");
	animnhanvat4 -> addSpriteFrameWithFileName("Falling_002.png");
	animnhanvat4 -> addSpriteFrameWithFileName("Falling_003.png");
	animnhanvat4 -> addSpriteFrameWithFileName("Falling_004.png");
	animnhanvat4 -> addSpriteFrameWithFileName("Falling_005.png");
	animnhanvat4 -> addSpriteFrameWithFileName("Falling_006.png");
	animnhanvat4 -> addSpriteFrameWithFileName("Falling_007.png");
	animnhanvat4 -> addSpriteFrameWithFileName("Falling_008.png");
	animnhanvat4 -> addSpriteFrameWithFileName("Falling_009.png");
	animnhanvat4 -> addSpriteFrameWithFileName("Falling_010.png");
	animnhanvat4 -> addSpriteFrameWithFileName("Falling_011.png");
	animnhanvat4 -> addSpriteFrameWithFileName("Falling_012.png");
	animnhanvat4 -> addSpriteFrameWithFileName("Falling_013.png");
	animnhanvat4 -> addSpriteFrameWithFileName("Falling_014.png");
	animnhanvat4 -> addSpriteFrameWithFileName("Falling_015.png");
	animnhanvat4 -> addSpriteFrameWithFileName("Falling_016.png");
	animnhanvat4 -> addSpriteFrameWithFileName("Falling_017.png");
	animnhanvat4->setLoops(-1);
	animnhanvat4->setDelayPerUnit(0.1f);

	CCScaleTo * scanhanvat = CCScaleTo::create(0, 2.5, 3.3);
	nhanvat -> runAction(scanhanvat);

	actnhanvat = CCAnimate::create(animnhanvat);
	actnhanvat -> retain();
	actnhanvat1 = CCAnimate::create(animnhanvat1);
	actnhanvat1 -> retain();
	actnhanvat2 = CCAnimate::create(animnhanvat2);
	actnhanvat2 -> retain();
	actnhanvat3 = CCAnimate::create(animnhanvat3);
	actnhanvat3 -> retain();
	actnhanvat4 = CCAnimate::create(animnhanvat4);
	actnhanvat4 -> retain();

	nhanvat->setPosition(ccp(50,300)); 
	nhanvat->runAction(actnhanvat);
	this->addChild(nhanvat); 
	_arrnhanvat -> addObject(nhanvat);
	
	labeldiem = CCLabelTTF::create("0", "Arial", TITLE_FONT_SIZE);
	labeldiem->setPosition(ccp(s.width/2, 1200));
	labeldiem -> setColor(ccc3(150,150,150));
	this->addChild(labeldiem, 1);

	this -> schedule(schedule_selector(HelloWorld::gameplay));
	this -> schedule( schedule_selector(HelloWorld::vacham));
	this -> schedule( schedule_selector(HelloWorld::update));
		
	diem = 0;
	setvachamchim = 0;
	setvachamsoc = 0;
	setvachambom = 0;
	time = 0;
	v= 450;
	vchim = 500;
	vquai = 600;
	vsoc = 75;
	vbom = 75;
	aa1=0;
	CCLayer* layerchim = CCLayer::create();
	this -> addChild(layerchim);
	layerchim -> setTag(10);

	CCLayer* layersoc = CCLayer::create();
	this -> addChild(layersoc);
	layersoc -> setTag(11);

	CCLayer* layerbom = CCLayer::create();
	this -> addChild(layerbom);
	layerbom -> setTag(12);

				system = CCParticleSystemQuad::create("Booster.plist");
				system->setTexture(CCTextureCache::sharedTextureCache()->addImage("point.png"));
				system->setLife(0.5);
				system->setLifeVar(0.5);
				//system->setAutoRemoveOnFinish(true);
				system -> setDuration(0.3);
				this->addChild(system,2);	
	this -> setTouchEnabled(true);
	this -> setTouchMode(kCCTouchesOneByOne);
}

void HelloWorld::addvatcan()
{
	CCSprite* vatcan = CCSprite::create("overhang.png");
	this->addChild(vatcan);
		
	if(rand() %2!=0)
	{
		aa1 =1;
		vatcan -> setPosition(ccp(s.width -60 , s.height + 100));
		vatcan -> setFlipX(1);
	}
	else
	{
		aa1 =1;
		vatcan -> setPosition(ccp(60 , s.height + 100));
	}
	_arrvatcan -> addObject(vatcan);
}

void HelloWorld::addquai()
{
	quai = CCSprite::create("climber_0000.png");
	CCAnimation* animquai = CCAnimation::create();
	animquai -> addSpriteFrameWithFileName("climber_0000.png");
	animquai -> addSpriteFrameWithFileName("climber_0001.png");
	animquai -> addSpriteFrameWithFileName("climber_0002.png");
	animquai -> addSpriteFrameWithFileName("climber_0003.png");
	animquai -> addSpriteFrameWithFileName("climber_0004.png");
	animquai -> addSpriteFrameWithFileName("climber_0005.png");
	animquai -> addSpriteFrameWithFileName("climber_0006.png");
	animquai -> addSpriteFrameWithFileName("climber_0007.png");
	animquai -> addSpriteFrameWithFileName("climber_0008.png");
	animquai -> addSpriteFrameWithFileName("climber_0009.png");
	animquai -> addSpriteFrameWithFileName("climber_0010.png");
	animquai -> addSpriteFrameWithFileName("climber_0011.png");
	animquai -> addSpriteFrameWithFileName("climber_0012.png");
	animquai -> addSpriteFrameWithFileName("climber_0013.png");
	animquai -> addSpriteFrameWithFileName("climber_0014.png");
	animquai -> addSpriteFrameWithFileName("climber_0015.png");
	animquai -> addSpriteFrameWithFileName("climber_0016.png");
	animquai -> setLoops(-1);
	animquai -> setDelayPerUnit(0.03f);
	
	CCActionInterval* actquai = CCAnimate::create(animquai);
		actquai -> retain();
		quai -> runAction(actquai);
	if(rand() % 2 ==1)
	{
		aa1 =1;
		quai -> setPosition(ccp(quai -> getContentSize().width + 15 , s.height + quai -> getContentSize().height));
		CCScaleTo* pcale2 = CCScaleTo::create(0,2.5,3.3);
		quai -> runAction(pcale2);
		
	}
	else
	{
		quai -> setPosition(ccp(s.width - quai -> getContentSize().width - 10, 
			s.height + quai -> getContentSize().height));
		CCScaleTo* pcale3 = CCScaleTo::create(0,2.5,3.3);
		quai -> runAction(pcale3);
		quai -> setFlipX(1);
	}
	this -> addChild(quai,1);
	_arrquai -> addObject(quai);
}

void HelloWorld::addchim()
{
	chim= CCSprite::create("chim_0000.png");
	CCAnimation* animchim = CCAnimation::create();
	animchim -> addSpriteFrameWithFileName("chim_0000.png");
	animchim -> addSpriteFrameWithFileName("chim_0001.png");
	animchim -> addSpriteFrameWithFileName("chim_0002.png");
	animchim -> addSpriteFrameWithFileName("chim_0003.png");
	animchim -> addSpriteFrameWithFileName("chim_0004.png");
	animchim -> addSpriteFrameWithFileName("chim_0005.png");
	animchim -> addSpriteFrameWithFileName("chim_0006.png");
	animchim -> addSpriteFrameWithFileName("chim_0007.png");
	animchim -> addSpriteFrameWithFileName("chim_0009.png");
	animchim -> addSpriteFrameWithFileName("chim_0010.png");
	animchim -> addSpriteFrameWithFileName("chim_0011.png");

	animchim -> setLoops(-1);
	animchim -> setDelayPerUnit(0.03f);
	chim -> runAction(CCAnimate::create(animchim));

	if(rand() % 2 ==1)
	{
		aa1 =1;
		chim -> setPosition(ccp(50,1000));
		CCScaleTo* pcale2 = CCScaleTo::create(0,2.5,3.3);
		chim -> runAction(pcale2);
		aa = 0;
	}
	else
	{
		chim -> setPosition(ccp(s.width - 50, 1000));
		CCScaleTo* pcale3 = CCScaleTo::create(0,2.5,3.3);
		chim -> runAction(pcale3);
		chim -> setFlipX(1);
		aa =1;
	}
	this -> addChild(chim,1);
	_arrchim -> addObject(chim);

}

void HelloWorld::addnvtieutrai()
{
	CCSprite * nvtieutrai = CCSprite::create("thrower.png");
		nvtieutrai -> setPosition(ccp(50, s.height + 100));
		this->addChild(nvtieutrai,2);
	CCScaleTo* scalenvtieu = CCScaleTo::create(0,3,3);
		nvtieutrai -> runAction(scalenvtieu);
		_arrnvtieutrai -> addObject(nvtieutrai);
	CCSprite* bomtrai  = CCSprite::create("bom_0000.png");
	CCAnimation* animbom = CCAnimation::create();
		animbom -> addSpriteFrameWithFileName("bom_0000.png");
		animbom -> addSpriteFrameWithFileName("bom_0001.png");
		animbom -> addSpriteFrameWithFileName("bom_0002.png");
		animbom -> addSpriteFrameWithFileName("bom_0003.png");
		animbom -> addSpriteFrameWithFileName("bom_0004.png");
		animbom -> addSpriteFrameWithFileName("bom_0005.png");
		animbom -> setLoops(-1);
		animbom -> setDelayPerUnit(0.03f);
		bomtrai -> runAction(CCAnimate::create(animbom));
		bomtrai -> setPosition(ccp(10,10));
		nvtieutrai -> addChild(bomtrai);
		
	CCScaleTo* scalebom = CCScaleTo::create(0,0.3,0.3);
		bomtrai -> runAction(scalebom);
		
}

void HelloWorld::addnvtieuphai()
{
	CCSprite * nvtieuphai = CCSprite::create("thrower.png");
		nvtieuphai -> setFlipX(true);
		nvtieuphai -> setPosition(ccp(s.width - 45, s.height + 100));
		this->addChild(nvtieuphai,2);
	CCScaleTo* scalenvtieu = CCScaleTo::create(0,3,3);
		nvtieuphai -> runAction(scalenvtieu);
		_arrnvtieuphai -> addObject(nvtieuphai);

	CCSprite* bomphai  = CCSprite::create("bom_0000.png");
	CCAnimation* animbomphai = CCAnimation::create();
		animbomphai -> addSpriteFrameWithFileName("bom_0000.png");
		animbomphai -> addSpriteFrameWithFileName("bom_0001.png");
		animbomphai -> addSpriteFrameWithFileName("bom_0002.png");
		animbomphai -> addSpriteFrameWithFileName("bom_0003.png");
		animbomphai -> addSpriteFrameWithFileName("bom_0004.png");
		animbomphai -> addSpriteFrameWithFileName("bom_0005.png");
		animbomphai -> setLoops(-1);
		animbomphai -> setDelayPerUnit(0.03f);
		bomphai -> runAction(CCAnimate::create(animbomphai));
		bomphai -> setPosition(ccp(20,20));
		nvtieuphai -> addChild(bomphai);
	CCScaleTo* scalebom = CCScaleTo::create(0,0.3,0.3);
		bomphai -> runAction(scalebom);
			
}

void HelloWorld::adddaytrai()
{
	CCSprite* daytrai = CCSprite::create("laundry.png");
		daytrai -> setPosition(ccp(s.width/2, s.height + 100));
		this -> addChild(daytrai);
	CCScaleTo* scaleday = CCScaleTo::create(0,3.2,1.5);
		daytrai -> runAction(scaleday);
		_arrdaytrai -> addObject(daytrai);
	
	CCSprite* soctrai = CCSprite::create("soc_0000.png");
	CCAnimation* animsoctrai = CCAnimation::create();
		animsoctrai -> addSpriteFrameWithFileName("soc_0000.png");
		animsoctrai -> addSpriteFrameWithFileName("soc_0001.png");
		animsoctrai -> addSpriteFrameWithFileName("soc_0002.png");
		animsoctrai -> addSpriteFrameWithFileName("soc_0003.png");
		animsoctrai -> addSpriteFrameWithFileName("soc_0004.png");
		animsoctrai -> addSpriteFrameWithFileName("soc_0005.png");
		animsoctrai -> addSpriteFrameWithFileName("soc_0006.png");
		animsoctrai -> addSpriteFrameWithFileName("soc_0007.png");
		animsoctrai -> setLoops(-1);
		animsoctrai -> setDelayPerUnit(0.04f);
		soctrai -> runAction(CCAnimate::create(animsoctrai));
		daytrai -> addChild(soctrai);
		soctrai -> setPosition(ccp(daytrai -> getContentSize().width - 20, 60));
		soctrai -> setFlipX(true);
	CCScaleTo * scasoc = CCScaleTo::create(0, 1, 2);
		soctrai -> runAction(scasoc);
		//_arrsoctrai -> addObject(soctrai);
}

void HelloWorld::adddayphai()
{
	CCSprite* dayphai = CCSprite::create("laundry.png");
		dayphai -> setPosition(ccp(s.width/2, s.height + 100));
		this -> addChild(dayphai);
	CCScaleTo* scaleday = CCScaleTo::create(0,3.2,1.5);
		dayphai -> runAction(scaleday);
		_arrdayphai -> addObject(dayphai);
	CCSprite* socphai = CCSprite::create("soc_0000.png");
	CCAnimation* animsocphai = CCAnimation::create();
		animsocphai -> addSpriteFrameWithFileName("soc_0000.png");
		animsocphai -> addSpriteFrameWithFileName("soc_0001.png");
		animsocphai -> addSpriteFrameWithFileName("soc_0002.png");
		animsocphai -> addSpriteFrameWithFileName("soc_0003.png");
		animsocphai -> addSpriteFrameWithFileName("soc_0004.png");
		animsocphai -> addSpriteFrameWithFileName("soc_0005.png");
		animsocphai -> addSpriteFrameWithFileName("soc_0006.png");
		animsocphai -> addSpriteFrameWithFileName("soc_0007.png");
		animsocphai -> setLoops(-1);
		animsocphai -> setDelayPerUnit(0.04f);
		socphai -> runAction(CCAnimate::create(animsocphai));
		dayphai -> addChild(socphai);
		socphai -> setPosition(ccp(20,65));
	CCScaleTo * scasoc = CCScaleTo::create(0, 1, 2);
		socphai -> runAction(scasoc);
		//_arrsocphai -> addObject(socphai);

}

void HelloWorld::vacham(float dt)
{
	//DelayTest *dlt = DelayTest::startDelayTest("vacham", 5000);
	CCObject* it = NULL;
	CCObject* jt = NULL;
	CCObject* kt = NULL;
	CCObject* nt = NULL;
	CCObject* mt = NULL;
	CCObject* ut = NULL;
	CCObject* vt = NULL;
	CCObject* yt = NULL;
	CCObject* zt = NULL;
	CCObject* at = NULL;
	CCObject* bt = NULL;
	CCRect nhanvatrect = CCRectMake(
		nhanvat->getPosition().x - (nhanvat->getContentSize().width/2),
		nhanvat->getPosition().y - (nhanvat->getContentSize().height/2),
		nhanvat->getContentSize().width,
		nhanvat->getContentSize().height);

	CCARRAY_FOREACH(_arrvatcan, it)
	{
		CCSprite *vatcan = dynamic_cast<CCSprite*>(it);
		CCRect vatcanrect = CCRectMake(
			vatcan->getPosition().x - (vatcan->getContentSize().width/2),
			vatcan->getPosition().y - (vatcan->getContentSize().height/2),
			vatcan->getContentSize().width,
			vatcan->getContentSize().height);
		if (nhanvatrect.intersectsRect(vatcanrect))
		{
			_arrvatcan -> removeObject(vatcan);
			this -> removeChild(vatcan);
			if(aa1=1)
			{
				nhanvat -> stopAllActions();
				nhanvat -> runAction(actnhanvat4);
				CCActionInterval* actionend1 = CCMoveTo::create(1,ccp(s.width/2, 200));
				CCActionInterval* actionend2 = CCMoveTo::create(4,ccp(s.width/2, 100));
				nhanvat -> runAction( CCSequence::create(actionend1,actionend2, NULL) );
				this -> schedule(schedule_selector(HelloWorld::end),1.8);
			}
			else
			{
				nhanvat -> stopAllActions();
				nhanvat -> runAction(actnhanvat4);
				CCActionInterval* actionend1 = CCMoveTo::create(1,ccp(s.width/2, 200));
				CCActionInterval* actionend2 = CCMoveTo::create(4,ccp(s.width/2, 100));
				nhanvat -> runAction( CCSequence::create(actionend1,actionend2, NULL) );
				this -> schedule(schedule_selector(HelloWorld::end),1.8);
				nhanvat -> setFlipX(true);
			}
		}

	}

	CCARRAY_FOREACH(_arrquai, jt)
	{
		CCSprite *quai = dynamic_cast<CCSprite*>(jt);
		CCRect quairect = CCRectMake(
			quai->getPosition().x - (quai->getContentSize().width/2 *getScaleX()),
			quai->getPosition().y - (quai->getContentSize().height/2 *getScaleY()),
			quai->getContentSize().width *getScaleX(),
			quai->getContentSize().height *getScaleY());
		if (nhanvatrect.intersectsRect(quairect))
		{
			_arrquai -> removeObject(quai);
			this -> removeChild(quai);
			if(aa1=1)
					{
					nhanvat -> stopAllActions();
					nhanvat -> runAction(actnhanvat4);
					CCActionInterval* actionend1 = CCMoveTo::create(1,ccp(s.width/2, 200));
					CCActionInterval* actionend2 = CCMoveTo::create(4,ccp(s.width/2, 100));
					nhanvat -> runAction( CCSequence::create(actionend1,actionend2, NULL) );
					this -> schedule(schedule_selector(HelloWorld::end),1.8);
					}
					else
					{
						nhanvat -> stopAllActions();
					nhanvat -> runAction(actnhanvat4);
					CCActionInterval* actionend1 = CCMoveTo::create(1,ccp(s.width/2, 200));
					CCActionInterval* actionend2 = CCMoveTo::create(4,ccp(s.width/2, 100));
					nhanvat -> runAction( CCSequence::create(actionend1,actionend2, NULL) );
					this -> schedule(schedule_selector(HelloWorld::end),1.8);
					nhanvat -> setFlipX(true);
					}
		}

	}	

	CCARRAY_FOREACH(_arrchim, kt)
	{
		CCSprite *chim = dynamic_cast<CCSprite*>(kt);
		CCRect chimrect = CCRectMake(
			chim->getPosition().x - (chim->getContentSize().width/2),
			chim->getPosition().y - (chim->getContentSize().height/2),
			chim->getContentSize().width,
			chim->getContentSize().height);
		if (nhanvatrect.intersectsRect(chimrect))
		{
			system -> resetSystem();
			system->setPosition(chim -> getPosition().x,chim -> getPosition().y);
			if(nhanvat -> getPosition().x == 50 || nhanvat -> getPosition().x ==670)
			{
				if(aa1=1)
					{
					nhanvat -> stopAllActions();
					nhanvat -> runAction(actnhanvat4);
					CCActionInterval* actionend1 = CCMoveTo::create(1,ccp(s.width/2, 200));
					CCActionInterval* actionend2 = CCMoveTo::create(4,ccp(s.width/2, 100));
					nhanvat -> runAction( CCSequence::create(actionend1,actionend2, NULL) );
					this -> schedule(schedule_selector(HelloWorld::end),1.8);
					}
					else
					{
						nhanvat -> stopAllActions();
					nhanvat -> runAction(actnhanvat4);
					CCActionInterval* actionend1 = CCMoveTo::create(1,ccp(s.width/2, 200));
					CCActionInterval* actionend2 = CCMoveTo::create(4,ccp(s.width/2, 100));
					nhanvat -> runAction( CCSequence::create(actionend1,actionend2, NULL) );
					this -> schedule(schedule_selector(HelloWorld::end),1.8);
					nhanvat -> setFlipX(true);
					}
			}
			else if(50 < nhanvat -> getPosition().x < 670)
			{
				
				_arrchim -> removeObject(chim);
				this -> removeChild(chim);
				setvachamchim +=1;
				setvachamsoc = 0;
				setvachambom = 0;
				CCLayer* layersoc = (CCLayer*)(this -> getChildByTag(11));
				layersoc -> removeAllChildren();	
				CCLayer* layerbom = (CCLayer*)(this -> getChildByTag(12));
				layerbom -> removeAllChildren();
				if(setvachamchim ==1)
				{
					CCSprite* vachamchim = CCSprite::create("chim_0003.png");
					vachamchim -> setPosition(ccp(100,80));
					CCScaleTo* scalevachamchim = CCScaleTo::create(0,2,2);
					vachamchim -> runAction(scalevachamchim);
					CCLayer* layerchim = (CCLayer*)(this -> getChildByTag(10));
					layerchim -> addChild(vachamchim);
				}

				if(setvachamchim ==2)
				{
					CCSprite* vachamchim = CCSprite::create("chim_0003.png");
					vachamchim -> setPosition(ccp(200,80));
					CCScaleTo* scalevachamchim = CCScaleTo::create(0,2,2);
					vachamchim -> runAction(scalevachamchim);
					CCLayer* layerchim = (CCLayer*)(this -> getChildByTag(10));
					layerchim -> addChild(vachamchim);
				}

				if(setvachamchim == 3)
				{
					
					CCSprite* vachamchim = CCSprite::create("chim_0003.png");
					vachamchim -> setPosition(ccp(300,80));
					CCScaleTo* scalevachamchim = CCScaleTo::create(0,2,2);
					vachamchim -> runAction(scalevachamchim);
					CCLayer* layerchim = (CCLayer*)(this -> getChildByTag(10));
					layerchim -> addChild(vachamchim);
					this -> schedule( schedule_selector(HelloWorld::callvachamchim),3.0);
					nhanvat -> stopAllActions();
					nhanvat -> runAction(actnhanvat2);
					ccBezierConfig bezierchim;
					bezierchim.controlPoint_1 = ccp(100, 1000);
					bezierchim.controlPoint_2 = ccp(200, 500);
					bezierchim.endPosition = ccp(670,300);
					CCActionInterval* bezierchim1 = CCBezierTo::create(5, bezierchim);
					CCFiniteTimeAction* actionMoveDone = 
						CCCallFuncN::create( this, 
						callfuncN_selector(HelloWorld::callfuntion));
					nhanvat -> runAction( CCSequence::create(bezierchim1, actionMoveDone, NULL) );
					nhanvat -> setFlipX(true);
					this -> schedule(schedule_selector(HelloWorld::combo));
					
				}

			}

		}

	}

	CCARRAY_FOREACH(_arrnvtieuphai, nt)
	{
		CCSprite *nvtieuphai = dynamic_cast<CCSprite*>(nt);
		CCRect nvtieuphairect = CCRectMake(
			nvtieuphai->getPosition().x - (nvtieuphai->getContentSize().width/2),
			nvtieuphai->getPosition().y - (nvtieuphai->getContentSize().height/2),
			nvtieuphai->getContentSize().width,
			nvtieuphai->getContentSize().height);
		if (nhanvatrect.intersectsRect(nvtieuphairect))
		{
			this -> removeChild(nvtieuphai);
			aa1=1;
				if(aa1==1)
				{
					nhanvat -> stopAllActions();
					nhanvat -> runAction(actnhanvat4);
					CCActionInterval* actionend1 = CCMoveTo::create(1,ccp(s.width/2, 200));
					CCActionInterval* actionend2 = CCMoveTo::create(4,ccp(s.width/2, 100));
					nhanvat -> runAction( CCSequence::create(actionend1,actionend2, NULL) );
					this -> schedule(schedule_selector(HelloWorld::end),2.0);
					nhanvat -> setFlipX(true);
				}
		}
		CCArray* bomphai = nvtieuphai -> getChildren();
	CCARRAY_FOREACH(bomphai, mt)
	{
		
		CCSprite *bomphai = dynamic_cast<CCSprite*>(mt);
		CCPoint point1 = bomphai->getParent()-> convertToWorldSpace(bomphai -> getPosition());
		CCRect bomphairect = CCRectMake(
			point1.x - (bomphai->getContentSize().width/2),
			point1.y - (bomphai->getContentSize().height/2),
			bomphai-> getContentSize().width,
			bomphai-> getContentSize().height);
		
		if (nhanvatrect.intersectsRect(bomphairect))
		{
			system -> resetSystem();
			system->setPosition(point1.x, point1.y);
				

			if(nhanvat -> getPosition().x == 50 || nhanvat -> getPosition().x ==670)
			{
				aa1=1;
				if(aa1==1)
				{
					nhanvat -> stopAllActions();
					nhanvat -> runAction(actnhanvat4);
					CCActionInterval* actionend1 = CCMoveTo::create(1,ccp(s.width/2, 200));
					CCActionInterval* actionend2 = CCMoveTo::create(4,ccp(s.width/2, 100));
					nhanvat -> runAction( CCSequence::create(actionend1,actionend2, NULL) );
					this -> schedule(schedule_selector(HelloWorld::end),2.0);
					nhanvat -> setFlipX(true);
				}
			}
			else if(50 < nhanvat -> getPosition().x < 670)
			{
				bomphai -> getParent() -> removeAllChildren();
				setvachambom +=1;
				setvachamchim = 0;
				setvachamsoc = 0;
				CCLayer* layerchim = (CCLayer*)(this -> getChildByTag(10));
				layerchim -> removeAllChildren();
				CCLayer* layersoc = (CCLayer*)(this -> getChildByTag(11));
				layersoc -> removeAllChildren();
				if(setvachambom == 1)
				{
					CCSprite* vachambom = CCSprite::create("bom_0000.png");
					vachambom -> setPosition(ccp(100,100));
					CCLayer* layerbom = (CCLayer*)(this -> getChildByTag(12));
					layerbom -> addChild(vachambom);
				}
				if(setvachambom == 2)
				{
					CCSprite* vachambom = CCSprite::create("bom_0000.png");
					vachambom -> setPosition(ccp(200,100));
					CCLayer* layerbom = (CCLayer*)(this -> getChildByTag(12));
					layerbom -> addChild(vachambom);
				}
				if(setvachambom == 3)
				{
					setvachambom = 0;
					CCSprite* vachambom = CCSprite::create("bom_0000.png");
					vachambom -> setPosition(ccp(300,100));
					CCLayer* layerbom = (CCLayer*)(this -> getChildByTag(12));
					layerbom -> addChild(vachambom);
					this -> schedule( schedule_selector(HelloWorld::callvachambom),3.0);
					nhanvat -> stopAllActions();
					nhanvat -> runAction(actnhanvat2);
					ccBezierConfig bezierchim;
					bezierchim.controlPoint_1 = ccp(100, 1000);
					bezierchim.controlPoint_2 = ccp(200, 500);
					bezierchim.endPosition = ccp(670,300);
					CCActionInterval* bezierchim1 = CCBezierTo::create(5, bezierchim);
					CCFiniteTimeAction* actionMoveDone = 
						CCCallFuncN::create( this, 
						callfuncN_selector(HelloWorld::callfuntion));
					nhanvat -> runAction( CCSequence::create(bezierchim1, actionMoveDone, NULL) );
					nhanvat -> setFlipX(true);
					this -> schedule(schedule_selector(HelloWorld::combo));
				}
			}
		}

	}
	}

	CCARRAY_FOREACH(_arrnvtieutrai, ut)
	{
		CCSprite *nvtieutrai = dynamic_cast<CCSprite*>(ut);
		CCRect nvtieutrairect = CCRectMake(
			nvtieutrai->getPosition().x - (nvtieutrai->getContentSize().width/2),
			nvtieutrai->getPosition().y - (nvtieutrai->getContentSize().height/2),
			nvtieutrai->getContentSize().width,
			nvtieutrai->getContentSize().height);
		if (nhanvatrect.intersectsRect(nvtieutrairect))
		{
			this -> removeChild(nvtieutrai);
			aa1=1;
				if(aa1==1)
				{
					nhanvat -> stopAllActions();
					nhanvat -> runAction(actnhanvat4);
					CCActionInterval* actionend1 = CCMoveTo::create(1,ccp(s.width/2, 200));
					CCActionInterval* actionend2 = CCMoveTo::create(4,ccp(s.width/2, 100));
					nhanvat -> runAction( CCSequence::create(actionend1,actionend2, NULL) );
					this -> schedule(schedule_selector(HelloWorld::end),2.0);
				}
		}
		CCArray* bomtrai = nvtieutrai -> getChildren();
	CCARRAY_FOREACH(bomtrai, vt)
	{
		CCSprite *bomtrai = dynamic_cast<CCSprite*>(vt);
		CCPoint point1 = bomtrai->getParent()-> convertToWorldSpace(bomtrai -> getPosition());
		CCRect bomtrairect = CCRectMake(
			point1.x - (bomtrai->getContentSize().width/2),
			point1.y - (bomtrai->getContentSize().height/2),
			bomtrai-> getContentSize().width,
			bomtrai-> getContentSize().height);
		
		if (nhanvatrect.intersectsRect(bomtrairect))
		{
			system -> resetSystem();
			system->setPosition(point1.x, point1.y);
				
				
			if(nhanvat -> getPosition().x == 50 || nhanvat -> getPosition().x ==670)
			{
				aa1=1;
				if(aa1==1)
				{
					nhanvat -> stopAllActions();
					nhanvat -> runAction(actnhanvat4);
					CCActionInterval* actionend1 = CCMoveTo::create(1,ccp(s.width/2, 200));
					CCActionInterval* actionend2 = CCMoveTo::create(4,ccp(s.width/2, 100));
					nhanvat -> runAction( CCSequence::create(actionend1,actionend2, NULL) );
					this -> schedule(schedule_selector(HelloWorld::end),2.0);
					nhanvat -> setFlipX(true);
				}
			}
			else if(50 < nhanvat -> getPosition().x < 670)
			{
				
				bomtrai -> getParent() -> removeAllChildren();
				setvachambom +=1;
				setvachamchim = 0;
				setvachamsoc = 0;
				CCLayer* layerchim = (CCLayer*)(this -> getChildByTag(10));
				layerchim -> removeAllChildren();
				CCLayer* layersoc = (CCLayer*)(this -> getChildByTag(11));
				layersoc -> removeAllChildren();
				if(setvachambom == 1)
				{
					CCSprite* vachambom = CCSprite::create("bom_0000.png");
					vachambom -> setPosition(ccp(100,100));
					CCLayer* layerbom = (CCLayer*)(this -> getChildByTag(12));
					layerbom -> addChild(vachambom);
				}
				if(setvachambom == 2)
				{
					CCSprite* vachambom = CCSprite::create("bom_0000.png");
					vachambom -> setPosition(ccp(200,100));
					CCLayer* layerbom = (CCLayer*)(this -> getChildByTag(12));
					layerbom -> addChild(vachambom);
				}
				if(setvachambom == 3)
				{
					setvachambom = 0;
					CCSprite* vachambom = CCSprite::create("bom_0000.png");
					vachambom -> setPosition(ccp(300,100));
					CCLayer* layerbom = (CCLayer*)(this -> getChildByTag(12));
					layerbom -> addChild(vachambom);
					this -> schedule( schedule_selector(HelloWorld::callvachambom),3.0);
					nhanvat -> stopAllActions();
					nhanvat -> runAction(actnhanvat2);
					ccBezierConfig bezierchim;
					bezierchim.controlPoint_1 = ccp(100, 1000);
					bezierchim.controlPoint_2 = ccp(200, 500);
					bezierchim.endPosition = ccp(670,300);
					CCActionInterval* bezierchim1 = CCBezierTo::create(5, bezierchim);
					CCFiniteTimeAction* actionMoveDone = 
						CCCallFuncN::create( this, 
						callfuncN_selector(HelloWorld::callfuntion));
					nhanvat -> runAction( CCSequence::create(bezierchim1, actionMoveDone, NULL) );
					nhanvat -> setFlipX(true);
					this -> schedule(schedule_selector(HelloWorld::combo));
				}
			}
		}

	}
	}

	CCARRAY_FOREACH(_arrdayphai, yt)
	{
		CCSprite *dayphai = dynamic_cast<CCSprite*>(yt);
		CCRect dayphairect = CCRectMake(
			dayphai->getPosition().x - (dayphai->getContentSize().width/2 *getScaleX()),
			dayphai->getPosition().y - (dayphai->getContentSize().height/2 *getScaleY()),
			dayphai->getContentSize().width *getScaleX(),
			dayphai->getContentSize().height *getScaleY());
		if (nhanvatrect.intersectsRect(dayphairect))
		{
			
		}
	CCArray* socphai = dayphai -> getChildren();
	CCARRAY_FOREACH(socphai, zt)
	{
		CCSprite *socphai = dynamic_cast<CCSprite*>(zt);
		CCPoint point = socphai -> getParent() -> convertToWorldSpace(socphai -> getPosition());
		CCRect socphairect = CCRectMake(
			point.x - (socphai->getContentSize().width/2 *3.2),
			point.y - (socphai->getContentSize().height/2 *3),
			socphai-> getContentSize().width *socphai -> getScaleX() *3.2,
			socphai-> getContentSize().height *socphai -> getScaleY() *3);
				
		if (nhanvatrect.intersectsRect(socphairect))
		{
				system -> resetSystem();
				system->setPosition(point.x, point.y);
			socphai -> getParent() -> removeAllChildren();
			if(nhanvat -> getPosition().x == 50 || nhanvat -> getPosition().x == 670)
			{
				aa1=1;
				if(aa1==1)
				{
					nhanvat -> stopAllActions();
					nhanvat -> runAction(actnhanvat4);
					CCActionInterval* actionend1 = CCMoveTo::create(1,ccp(s.width/2, 200));
					CCActionInterval* actionend2 = CCMoveTo::create(4,ccp(s.width/2, 100));
					nhanvat -> runAction( CCSequence::create(actionend1,actionend2, NULL) );
					this -> schedule(schedule_selector(HelloWorld::end),2.0);
					nhanvat -> setFlipX(true);
				}
			}
			else if(50 < nhanvat -> getPosition().x < 670)
			{
				//_arrdayphai -> removeObject(dayphai);
				setvachamsoc +=1;
				setvachamchim = 0;
				setvachambom = 0;

				CCLayer* layerchim = (CCLayer*)(this -> getChildByTag(10));
				layerchim -> removeAllChildren();
				CCLayer* layerbom = (CCLayer*)(this -> getChildByTag(12));
				layerbom -> removeAllChildren();
				if(setvachamsoc == 1)
				{
					CCSprite* vachamsoc = CCSprite::create("soc_0007.png");
					vachamsoc -> setPosition(ccp(100,80));
					CCScaleTo* scalevachamsoc = CCScaleTo::create(0,2,2);
					vachamsoc -> runAction(scalevachamsoc);
					CCLayer* layersoc = (CCLayer*)(this -> getChildByTag(11));
					layersoc -> addChild(vachamsoc);
				}
				if(setvachamsoc == 2)
				{
					
					CCSprite* vachamsoc = CCSprite::create("soc_0007.png");
					vachamsoc -> setPosition(ccp(200,80));
					CCScaleTo* scalevachamsoc = CCScaleTo::create(0,2,2);
					vachamsoc -> runAction(scalevachamsoc);
					CCLayer* layersoc = (CCLayer*)(this -> getChildByTag(11));
					layersoc -> addChild(vachamsoc);
				}
				if(setvachamsoc == 3)
				{
				
					setvachamsoc = 0;
					CCSprite* vachamsoc = CCSprite::create("soc_0007.png");
					vachamsoc -> setPosition(ccp(300,80));
					CCScaleTo* scalevachamsoc = CCScaleTo::create(0,2,2);
					vachamsoc -> runAction(scalevachamsoc);
					CCLayer* layersoc = (CCLayer*)(this -> getChildByTag(11));
					layersoc -> addChild(vachamsoc);
					this -> schedule( schedule_selector(HelloWorld::callvachamsoc),3.0);
					nhanvat -> stopAllActions();
					nhanvat -> runAction(actnhanvat2);
					ccBezierConfig bezierchim;
					bezierchim.controlPoint_1 = ccp(50,500);
					bezierchim.controlPoint_2 = ccp(670, 700);
					bezierchim.endPosition = ccp(670,300);
					CCActionInterval* bezierchim1 = CCBezierTo::create(5, bezierchim);
					CCFiniteTimeAction* actionMoveDone = CCCallFuncN::create( this, 
						callfuncN_selector(HelloWorld::callfuntion));
					nhanvat -> runAction( CCSequence::create(bezierchim1, actionMoveDone, NULL) );
					nhanvat -> setFlipX(true);
					this -> schedule(schedule_selector(HelloWorld::combo));
				}
			}
			
		}
	}
}	
	
	CCARRAY_FOREACH(_arrdaytrai, at)
	{
		CCSprite *daytrai = dynamic_cast<CCSprite*>(at);
		CCRect daytrairect = CCRectMake(
			daytrai->getPosition().x - (daytrai->getContentSize().width/2 *getScaleX()),
			daytrai->getPosition().y - (daytrai->getContentSize().height/2 *getScaleY()),
			daytrai->getContentSize().width *getScaleX(),
			daytrai->getContentSize().height *getScaleY());
		if (nhanvatrect.intersectsRect(daytrairect))
		{
			
		}
	CCArray* soctrai = daytrai -> getChildren();
	CCARRAY_FOREACH(soctrai, bt)
	{

		CCSprite *soctrai = dynamic_cast<CCSprite*>(bt);
		CCPoint point = soctrai -> getParent() -> convertToWorldSpace(soctrai -> getPosition());
		CCRect soctrairect = CCRectMake(
			point.x - (soctrai->getContentSize().width/2 *3.2),
			point.y - (soctrai->getContentSize().height/2 *3),
			soctrai-> getContentSize().width *soctrai -> getScaleX() *3.2,
			soctrai-> getContentSize().height *soctrai -> getScaleY() *3);
				
		if (nhanvatrect.intersectsRect(soctrairect))
		{
			system -> resetSystem();
				system->setPosition(point.x, point.y);
		if(nhanvat -> getPosition().x == 50 || nhanvat -> getPosition().x == 670)
			{
				
				aa1=1;
				if(aa1==1)
				{
					nhanvat -> stopAllActions();
					nhanvat -> runAction(actnhanvat4);
					CCActionInterval* actionend1 = CCMoveTo::create(1,ccp(s.width/2, 200));
					CCActionInterval* actionend2 = CCMoveTo::create(4,ccp(s.width/2, 100));
					nhanvat -> runAction( CCSequence::create(actionend1,actionend2, NULL) );
					this -> schedule(schedule_selector(HelloWorld::end),2.0);
			
				}
			}
			else if(50 < nhanvat -> getPosition().x < 670)
			{
				//_arrdaytrai -> removeObject(daytrai);
				soctrai -> getParent() -> removeAllChildren();
				setvachamsoc +=1;
				setvachamchim = 0;
				setvachambom = 0;

				CCLayer* layerchim = (CCLayer*)(this -> getChildByTag(10));
				layerchim -> removeAllChildren();
				CCLayer* layerbom = (CCLayer*)(this -> getChildByTag(12));
				layerbom -> removeAllChildren();
				if(setvachamsoc == 1)
				{
					CCSprite* vachamsoc = CCSprite::create("soc_0007.png");
					vachamsoc -> setPosition(ccp(100,80));
					CCScaleTo* scalevachamsoc = CCScaleTo::create(0,2,2);
					vachamsoc -> runAction(scalevachamsoc);
					CCLayer* layersoc = (CCLayer*)(this -> getChildByTag(11));
					layersoc -> addChild(vachamsoc);
				}
				if(setvachamsoc == 2)
				{
					
					CCSprite* vachamsoc = CCSprite::create("soc_0007.png");
					vachamsoc -> setPosition(ccp(200,80));
					CCScaleTo* scalevachamsoc = CCScaleTo::create(0,2,2);
					vachamsoc -> runAction(scalevachamsoc);
					CCLayer* layersoc = (CCLayer*)(this -> getChildByTag(11));
					layersoc -> addChild(vachamsoc);
				}
				if(setvachamsoc == 3)
				{
				
					setvachamsoc = 0;
					CCSprite* vachamsoc = CCSprite::create("soc_0007.png");
					vachamsoc -> setPosition(ccp(300,80));
					CCScaleTo* scalevachamsoc = CCScaleTo::create(0,2,2);
					vachamsoc -> runAction(scalevachamsoc);
					CCLayer* layersoc = (CCLayer*)(this -> getChildByTag(11));
					layersoc -> addChild(vachamsoc);
					this -> schedule( schedule_selector(HelloWorld::callvachamsoc),3.0);
					nhanvat -> stopAllActions();
					nhanvat -> runAction(actnhanvat2);
					ccBezierConfig bezierchim;
					bezierchim.controlPoint_1 = ccp(50,500);
					bezierchim.controlPoint_2 = ccp(670, 700);
					bezierchim.endPosition = ccp(670,300);
					CCActionInterval* bezierchim1 = CCBezierTo::create(5, bezierchim);
					CCFiniteTimeAction* actionMoveDone = CCCallFuncN::create( this, 
						callfuncN_selector(HelloWorld::callfuntion));
					nhanvat -> runAction( CCSequence::create(bezierchim1, actionMoveDone, NULL) );
					nhanvat -> setFlipX(true);
					this -> schedule(schedule_selector(HelloWorld::combo));
				}
			}
			
		}
	}
}

}

void HelloWorld::vachamcombo(float dt)
{
	CCObject* it = NULL;
	CCObject* jt = NULL;
	CCObject* kt = NULL;
	CCObject* nt = NULL;
	CCObject* mt = NULL;
	CCObject* ut = NULL;
	CCObject* vt = NULL;
	CCObject* yt = NULL;
	CCObject* zt = NULL;
	CCObject* at = NULL;
	CCObject* bt = NULL;
	CCRect nhanvatrect = CCRectMake(
		nhanvat->getPosition().x - (nhanvat->getContentSize().width/2),
		nhanvat->getPosition().y - (nhanvat->getContentSize().height/2),
		nhanvat->getContentSize().width,
		nhanvat->getContentSize().height);

	CCARRAY_FOREACH(_arrvatcan, it)
	{
		CCSprite *vatcan = dynamic_cast<CCSprite*>(it);
		CCRect vatcanrect = CCRectMake(
			vatcan->getPosition().x - (vatcan->getContentSize().width/2),
			vatcan->getPosition().y - (vatcan->getContentSize().height/2),
			vatcan->getContentSize().width,
			vatcan->getContentSize().height);
		if (nhanvatrect.intersectsRect(vatcanrect))
		{
			_arrvatcan -> removeObject(vatcan);
			this -> removeChild(vatcan);
		}
	}

	CCARRAY_FOREACH(_arrquai, jt)
	{
		CCSprite *quai = dynamic_cast<CCSprite*>(jt);
		CCRect quairect = CCRectMake(
			quai->getPosition().x - (quai->getContentSize().width/2 *getScaleX()),
			quai->getPosition().y - (quai->getContentSize().height/2 *getScaleY()),
			quai->getContentSize().width *getScaleX(),
			quai->getContentSize().height *getScaleY());
		if (nhanvatrect.intersectsRect(quairect))
		{
			_arrquai -> removeObject(quai);
			this -> removeChild(quai);
		}
	}	

	CCARRAY_FOREACH(_arrchim, kt)
	{
		CCSprite *chim = dynamic_cast<CCSprite*>(kt);
		CCRect chimrect = CCRectMake(
			chim->getPosition().x - (chim->getContentSize().width/2),
			chim->getPosition().y - (chim->getContentSize().height/2),
			chim->getContentSize().width,
			chim->getContentSize().height);
		if (nhanvatrect.intersectsRect(chimrect))
		{
			system -> resetSystem();
			system->setPosition(chim -> getPosition().x,chim -> getPosition().y);
			_arrchim -> removeObject(chim);
			this -> removeChild(chim);
		}
	}

	CCARRAY_FOREACH(_arrnvtieuphai, nt)
	{
		CCSprite *nvtieuphai = dynamic_cast<CCSprite*>(nt);
		CCRect nvtieuphairect = CCRectMake(
			nvtieuphai->getPosition().x - (nvtieuphai->getContentSize().width/2),
			nvtieuphai->getPosition().y - (nvtieuphai->getContentSize().height/2),
			nvtieuphai->getContentSize().width,
			nvtieuphai->getContentSize().height);
		if (nhanvatrect.intersectsRect(nvtieuphairect))
		{
			_arrnvtieuphai -> removeObject(nvtieuphai);
			this -> removeChild(nvtieuphai);
		}
		CCArray* bomphai = nvtieuphai -> getChildren();
	CCARRAY_FOREACH(bomphai, mt)
	{
		
		CCSprite *bomphai = dynamic_cast<CCSprite*>(mt);
		CCPoint point1 = bomphai->getParent()-> convertToWorldSpace(bomphai -> getPosition());
		CCRect bomphairect = CCRectMake(
			point1.x - (bomphai->getContentSize().width/2),
			point1.y - (bomphai->getContentSize().height/2),
			bomphai-> getContentSize().width,
			bomphai-> getContentSize().height);
		
		if (nhanvatrect.intersectsRect(bomphairect))
		{
			system -> resetSystem();
			system->setPosition(point1.x, point1.y);
			bomphai -> getParent() -> removeAllChildren();
		}
	}
	}

	CCARRAY_FOREACH(_arrnvtieutrai, ut)
	{
		CCSprite *nvtieutrai = dynamic_cast<CCSprite*>(ut);
		CCRect nvtieutrairect = CCRectMake(
			nvtieutrai->getPosition().x - (nvtieutrai->getContentSize().width/2),
			nvtieutrai->getPosition().y - (nvtieutrai->getContentSize().height/2),
			nvtieutrai->getContentSize().width,
			nvtieutrai->getContentSize().height);
		if (nhanvatrect.intersectsRect(nvtieutrairect))
		{
			_arrnvtieutrai -> removeObject(nvtieutrai);
			this -> removeChild(nvtieutrai);
		}
		CCArray* bomtrai = nvtieutrai -> getChildren();

	CCARRAY_FOREACH(bomtrai, vt)
	{
		CCSprite *bomtrai = dynamic_cast<CCSprite*>(vt);
		CCPoint point1 = bomtrai->getParent()-> convertToWorldSpace(bomtrai -> getPosition());
		CCRect bomtrairect = CCRectMake(
			point1.x - (bomtrai->getContentSize().width/2),
			point1.y - (bomtrai->getContentSize().height/2),
			bomtrai-> getContentSize().width,
			bomtrai-> getContentSize().height);
		
		if (nhanvatrect.intersectsRect(bomtrairect))
		{
			system -> resetSystem();
			system->setPosition(point1.x, point1.y);
			bomtrai -> getParent() -> removeAllChildren();
		}
	}
	}

	CCARRAY_FOREACH(_arrdayphai, yt)
	{
		CCSprite *dayphai = dynamic_cast<CCSprite*>(yt);
		CCRect dayphairect = CCRectMake(
			dayphai->getPosition().x - (dayphai->getContentSize().width/2 *getScaleX()),
			dayphai->getPosition().y - (dayphai->getContentSize().height/2 *getScaleY()),
			dayphai->getContentSize().width *getScaleX(),
			dayphai->getContentSize().height *getScaleY());
		if (nhanvatrect.intersectsRect(dayphairect))
		{
			
		}
		CCArray* socphai = dayphai -> getChildren();
	CCARRAY_FOREACH(socphai, zt)
	{
		CCSprite *socphai = dynamic_cast<CCSprite*>(zt);
		CCPoint point = socphai -> getParent() -> convertToWorldSpace(socphai -> getPosition());
		CCRect socphairect = CCRectMake(
			point.x - (socphai->getContentSize().width/2 *3.2),
			point.y - (socphai->getContentSize().height/2 *3),
			socphai-> getContentSize().width *socphai -> getScaleX() *3.2,
			socphai-> getContentSize().height *socphai -> getScaleY() *3);
				
		if (nhanvatrect.intersectsRect(socphairect))
		{
			system -> resetSystem();
			system->setPosition(point.x, point.y);
			socphai -> getParent() -> removeAllChildren();
		}
	}
	}	
	
	CCARRAY_FOREACH(_arrdaytrai, at)
	{
		CCSprite *daytrai = dynamic_cast<CCSprite*>(at);
		CCRect daytrairect = CCRectMake(
			daytrai->getPosition().x - (daytrai->getContentSize().width/2 *getScaleX()),
			daytrai->getPosition().y - (daytrai->getContentSize().height/2 *getScaleY()),
			daytrai->getContentSize().width *getScaleX(),
			daytrai->getContentSize().height *getScaleY());
		if (nhanvatrect.intersectsRect(daytrairect))
		{
			
		}
		CCArray* soctrai = daytrai -> getChildren();
	CCARRAY_FOREACH(soctrai, bt)
	{
		CCSprite *soctrai = dynamic_cast<CCSprite*>(bt);
		CCPoint point = soctrai -> getParent() -> convertToWorldSpace(soctrai -> getPosition());
		CCRect soctrairect = CCRectMake(
			point.x - (soctrai->getContentSize().width/2 *3.2),
			point.y - (soctrai->getContentSize().height/2 *3),
			soctrai-> getContentSize().width *soctrai -> getScaleX() *3.2,
			soctrai-> getContentSize().height *soctrai -> getScaleY() *3);
				
		if (nhanvatrect.intersectsRect(soctrairect))
		{
			system -> resetSystem();
			system->setPosition(point.x, point.y);
			soctrai -> getParent() -> removeAllChildren();
		}
	}
	}
}

void HelloWorld::update(float dt)
{
	// set chuyen dong 
	for(int i= 0; i < _arrnvtieuphai->count(); i++) 
	{
		CCSprite *rock = (CCSprite*) _arrnvtieuphai->objectAtIndex(i);
		float y = rock->getPositionY();
		rock->setPositionY(y- v*dt);
		CCArray* a = rock -> getChildren();
		for(int j= 0; j < a ->count(); j++)
		{
		CCSprite* aa = (CCSprite*) a ->objectAtIndex(j);
		float y = aa -> getPositionY();
		float x = aa ->getPositionX();
		aa->setPositionX(x - vbom*dt);
		aa -> setPositionY(y + 0.4);
		}
	}
	for(int i= 0; i < _arrnvtieutrai->count(); i++) 
	{
		CCSprite *rock = (CCSprite*) _arrnvtieutrai->objectAtIndex(i);
		float y = rock->getPositionY();
		rock->setPositionY(y- v*dt);
		CCArray* a = rock -> getChildren();
		for(int j= 0; j < a ->count(); j++)
		{
		CCSprite* aa = (CCSprite*) a ->objectAtIndex(j);
		float y = aa -> getPositionY();
		float x = aa ->getPositionX();
		aa->setPositionX(x + vbom*dt);
		aa -> setPositionY(y + 0.4);
		}
	}
	
	for(int i= 0; i < _arrtuongphai->count(); i++) 
	{
		CCSprite *rock = (CCSprite*) _arrtuongphai->objectAtIndex(i);
		float y = rock->getPositionY();
		rock->setPositionY(y- v*dt);
		if(rock -> getPosition().y < -rock -> getContentSize().height )
		{
			if(i == 0){
				CCSprite *rock2 = (CCSprite*) _arrtuongphai->objectAtIndex(24);
				rock -> setPositionY(rock2->getPosition().y+rock -> getContentSize().height);
			}else{
				CCSprite *rock2 = (CCSprite*) _arrtuongphai->objectAtIndex(i-1);
				rock -> setPositionY(rock2->getPosition().y+rock -> getContentSize().height);
			}
			/*rock -> setPositionY(19* rock -> getContentSize().height);*/
		}
		
    } 

	for(int i= 0; i < _arrtuongtrai->count(); i++) 
	{
		 CCSprite *rock1 = (CCSprite*) _arrtuongtrai->objectAtIndex(i);
		float y = rock1->getPositionY();
		rock1->setPositionY(y- v*dt);
		if(rock1 -> getPosition().y <= - rock1 -> getContentSize().height)
		{
			if(i == 0){
				CCSprite *rock2 = (CCSprite*) _arrtuongtrai->objectAtIndex(24);
				rock1 -> setPositionY(rock2->getPosition().y+rock1 -> getContentSize().height);
			}else{
				CCSprite *rock2 = (CCSprite*) _arrtuongtrai->objectAtIndex(i-1);
				rock1 -> setPositionY(rock2->getPosition().y+rock1 -> getContentSize().height);
			}
			/*rock -> setPositionY(19* rock -> getContentSize().height);*/
		}

		
    } 

	for(int i= 0; i < _arrvatcan->count(); i++) 
	{
		 CCSprite *rock = (CCSprite*) _arrvatcan->objectAtIndex(i);
		float y = rock->getPositionY();
		rock->setPositionY(y- v*dt);
	}

	for(int i= 0; i < _arrquai->count(); i++) 
	{
		 CCSprite *rock = (CCSprite*) _arrquai->objectAtIndex(i);
		float y = rock->getPositionY();
		rock->setPositionY(y- vquai*dt);
	}
	
	for(int i= 0; i < _arrchim->count(); i++) 
	{
		CCSprite *rock = (CCSprite*) _arrchim->objectAtIndex(i);
		float y = rock->getPositionY();
		float x = rock-> getPositionX();
		if(aa == 0)
		{
			rock->setPositionY((y - vchim*dt) - 1);
			rock->setPositionX(x + vchim*dt);
		}
		if(aa==1)
		{
			rock->setPositionY((y - vchim*dt) - 1);
			rock->setPositionX(x- vchim*dt);
		}
		
	}
	for(int i= 0; i < _arrdayphai->count(); i++) 
	{
		 CCSprite *rock = (CCSprite*) _arrdayphai->objectAtIndex(i);
		float y = rock->getPositionY();
		rock->setPositionY(y- v*dt);
		CCArray* a = rock -> getChildren();
		for(int j= 0; j < a ->count(); j++)
		{
		CCSprite* aa = (CCSprite*) a ->objectAtIndex(j);;
		float x = aa->getPositionX();
		aa->setPositionX(x + vsoc*dt);
		}

	}
	
	for(int i= 0; i < _arrdaytrai->count(); i++) 
	{
		 CCSprite *rock = (CCSprite*) _arrdaytrai->objectAtIndex(i);
		float y = rock->getPositionY();
		rock->setPositionY(y- v*dt);
		CCArray* a = rock -> getChildren();
		for(int j= 0; j < a ->count(); j++)
		{
		CCSprite *aa = (CCSprite*) a->objectAtIndex(j);

		float x = aa->getPositionX();
		aa->setPositionX(x - vsoc*dt);
		}

	}

	////remove khoi mang va xoa anh

	for(int i = 0; i< _arrvatcan -> count(); i++)
	{
		CCSprite* xoavatcan = (CCSprite*)_arrvatcan -> objectAtIndex(i);
		if(xoavatcan -> getPosition().y< -100)
		{
			this -> removeChild(xoavatcan);
			_arrvatcan -> removeObject(xoavatcan);
		
		}
	}
	
	for(int i = 0; i< _arrquai -> count(); i++)
	{
		CCSprite* xoaquai = (CCSprite*)_arrquai -> objectAtIndex(i);
		if(xoaquai -> getPosition().y< -100)
		{
			this -> removeChild(xoaquai);
			_arrquai -> removeObject(xoaquai);
		
		}
	}

	for(int i = 0; i< _arrchim -> count(); i++)
	{
		CCSprite* aaa = (CCSprite*)_arrchim -> objectAtIndex(i);
		if(aaa -> getPosition().x < -100 || aaa -> getPosition().x > 820)
		{
				this -> removeChild(aaa);
			_arrchim -> removeObject(aaa);
		
		}
	}

	for(int i = 0; i< _arrdayphai -> count(); i++)
	{
		CCSprite* xoadayphai = (CCSprite*)_arrdayphai -> objectAtIndex(i);
		if(xoadayphai -> getPosition().y < -100 )
		{
				this -> removeChild(xoadayphai);
			_arrdayphai -> removeObject(xoadayphai);
		
		}

	}
	for(int i = 0; i< _arrdaytrai -> count(); i++)
	{
		CCSprite* xoadaytrai = (CCSprite*)_arrdaytrai -> objectAtIndex(i);
		if(xoadaytrai -> getPosition().y< -100)
		{
				this -> removeChild(xoadaytrai);
			_arrdaytrai -> removeObject(xoadaytrai);
		
		}
	}

	for(int i = 0; i< _arrnvtieuphai -> count(); i++)
	{
		CCSprite* xoanvtieuphai = (CCSprite*)_arrnvtieuphai -> objectAtIndex(i);
		if(xoanvtieuphai -> getPosition().y< -100)
		{
				this -> removeChild(xoanvtieuphai);
			_arrnvtieuphai -> removeObject(xoanvtieuphai);
		
		}
	}

	for(int i = 0; i< _arrnvtieutrai -> count(); i++)
	{
		CCSprite* xoanvtieutrai = (CCSprite*)_arrnvtieutrai -> objectAtIndex(i);
		if(xoanvtieutrai -> getPosition().y< -100)
		{
			CCLog("toa do nv tieu trai : %d",xoanvtieutrai -> getPosition().y);
				this -> removeChild(xoanvtieutrai);
			_arrnvtieutrai -> removeObject(xoanvtieutrai);
			
		}
	}

	/*for(int i = 0; i< _arrtuongphai -> count(); i++)
	{
		CCSprite* aaa = (CCSprite*)_arrtuongphai -> objectAtIndex(i);
		if(aaa -> getPosition().y< -70)
		{
			CCLog("toa do nv tieu trai : %d",aaa -> getPosition().y);
				this -> removeChild(aaa);
			_arrtuongphai -> removeObject(aaa);
			
		
		}
	}

	for(int i = 0; i< _arrtuongtrai -> count(); i++)
	{
		CCSprite* aaa1 = (CCSprite*)_arrtuongtrai -> objectAtIndex(i);
		if(aaa1 -> getPosition().y<-70)
		{
				this -> removeChild(aaa1);
			_arrtuongtrai -> removeObject(aaa1);
		
		}
	}*/
	
	time+=dt;
	if(time > 0.03f)
	{
		diem += 1;
		time = 0;
		char strdiem[30] = {0};
		sprintf(strdiem, "%d", diem);
		labeldiem -> setString(strdiem);
	}
}

void HelloWorld::combo(float dt)
{
	v = 900;
	vchim = 1000;
	vquai = 1200;
	vsoc = 150;
	vbom = 150;
	this -> schedule(schedule_selector(HelloWorld::endcombo),5.0);
	this -> unschedule(schedule_selector(HelloWorld::vacham));
	this -> schedule(schedule_selector(HelloWorld::vachamcombo));
}

void HelloWorld::endcombo(float dt)
{
	this -> unschedule(schedule_selector(HelloWorld::combo));
	this -> unschedule(schedule_selector(HelloWorld::vachamcombo));
	this -> schedule(schedule_selector(HelloWorld::vacham));
	v = 450;
	vchim = 500;
	vquai = 600;
	vsoc = 75;
	vbom = 75;

}

void HelloWorld::end(float dt)
{
	CCDirector::sharedDirector()->end();
}

void HelloWorld::spriteMoveFinished(CCNode* sender)
{
	CCSprite *sprite = (CCSprite *)sender;
	this->removeChild(sprite, true);
}

bool HelloWorld::ccTouchBegan(CCTouch *pTouch, CCEvent *pEvent)
{
	CCPoint location = pTouch->getLocationInView();
	location = CCDirector::sharedDirector()->convertToGL(location);

	if(location.x < 0)
		location.x = 0;
	if(location.x > s.width)
		location.x = s.width;
	
	//CCLog("quai:" "%d", _arrquai -> count());
	//CCLog("nhanvat:" "%d", _arrnhanvat -> count());
	//CCLog("vatcan:" "%d", _arrvatcan -> count());
	//CCLog("tuongphai:" "%d", _arrtuongphai -> count());
	//CCLog("tuongtrai:" "%d", _arrtuongtrai -> count());
	//CCLog("setvacham:" "%d", setvacham);
	//CCLog("soc:" "%d", _arrsoc -> count());
	if(nhanvat -> getPosition().x <= 50 )
	{	
		nhanvat -> stopAllActions();
		nhanvat -> runAction(actnhanvat1);
		ccBezierConfig bezier2;
		bezier2.controlPoint_1 = ccp(150, 450);
		bezier2.controlPoint_2 = ccp(600, 450);
		bezier2.endPosition = ccp(670,300);
		CCActionInterval* bezierTo1 = CCBezierTo::create(0.35, bezier2);
		CCFiniteTimeAction* actionMoveDone = 
			CCCallFuncN::create( this, 
			callfuncN_selector(HelloWorld::callfuntion));
		nhanvat -> runAction( CCSequence::create(bezierTo1, actionMoveDone, NULL));
		nhanvat -> setFlipX(true);	
	}
	if(670 <= nhanvat -> getPosition().x)
	{
		nhanvat -> stopAllActions();
		nhanvat -> stopAction(actnhanvat);
		nhanvat -> runAction(actnhanvat1);
		ccBezierConfig bezier2;
		bezier2.controlPoint_1 = ccp(570, 450);
		bezier2.controlPoint_2 = ccp(120, 450);
		bezier2.endPosition = ccp(50,300);
		CCActionInterval* bezierTo1 = CCBezierTo::create(0.35, bezier2);
		CCFiniteTimeAction* actionMoveDone = 
			CCCallFuncN::create( this, 
			callfuncN_selector(HelloWorld::callfuntion));
		nhanvat -> runAction( CCSequence::create(bezierTo1, actionMoveDone, NULL) );
		nhanvat -> setFlipX(false);	
	}

	return true;
}

void HelloWorld::onTouchMoved(CCTouch touch, CCEvent* event)
{

}

void HelloWorld::onTouchEnded(CCTouch touch, CCEvent* event)
{

}

void HelloWorld::callfuntion(CCNode* sender)
{
	nhanvat -> stopAllActions();
	nhanvat -> runAction(actnhanvat);
}

void HelloWorld::callvachamchim(float dt)
{
	CCLayer* layerchim = (CCLayer*)(this -> getChildByTag(10));
	layerchim -> removeAllChildren();	
	this -> unschedule( schedule_selector(HelloWorld::callvachamchim));
}

void HelloWorld::callvachamsoc(float dt)
{
	CCLayer* layersoc = (CCLayer*)(this -> getChildByTag(11));
	layersoc -> removeAllChildren();	
	this -> unschedule( schedule_selector(HelloWorld::callvachamsoc));
}

void HelloWorld::callvachambom(float dt)
{
	CCLayer* layersoc = (CCLayer*)(this -> getChildByTag(12));
	layersoc -> removeAllChildren();	
	this -> unschedule( schedule_selector(HelloWorld::callvachambom));
}

void HelloWorld::calllich(float dt)
{
	int t = rand() % 7;
		if(t==0)
		{ 
			this -> addnvtieuphai();
		}
		if(t == 1)
		{ 
			this -> adddayphai();
		}
		if(t == 2)
		{ 
			this -> addquai();
		}
		if(t == 3)
		{ 
			this -> addvatcan();
		}
		if(t == 4)
		{ 
			this -> adddaytrai();
		}
		if(t == 5)
		{ 
			this -> addchim();
		}
		if(t == 6)
		{ 
			this -> addnvtieutrai();
		}
}

void HelloWorld::gameplay(float dt)
{
	/*if(100 <= diem <200 )
	{
		v = 220;
		vquai = 330;
	}
	if(200 <= diem <300 )
	{
		v = 240;
		vquai = 360;
	}
	if(300 <= diem <400 )
	{
		v = 260;
		vquai = 390;
	}
	if(400 <= diem < 500 )
	{
		v = 280;
		vquai = 420;
	}
	if(500 <= diem <600)
	{
		v = 300;
		vquai = 450;
	}*/

	this -> schedule(schedule_selector(HelloWorld::calllich),3.0);
	if(500 <= diem)
	{
		this -> schedule(schedule_selector(HelloWorld::calllich),2.5);
	}
	if(1000 <= diem)
	{
		this -> schedule(schedule_selector(HelloWorld::calllich),2.0);
	}
}

void HelloWorld::gamepause(CCObject* pSender)
{
	this -> unschedule(schedule_selector(HelloWorld::update));
	this -> unschedule(schedule_selector(HelloWorld::gameplay));
	this -> unschedule(schedule_selector(HelloWorld::calllich));
	for(int i = 0; i < _arrquai -> count(); i++)
	{
		CCSprite* pausequai = (CCSprite*)_arrquai -> objectAtIndex(i);
		pausequai -> pauseSchedulerAndActions();
	}
	for(int i = 0; i < _arrnhanvat -> count(); i++)
	{
		CCSprite* pausenhanvat = (CCSprite*)_arrnhanvat -> objectAtIndex(i);
		pausenhanvat -> pauseSchedulerAndActions();
	}
	for(int i = 0; i < _arrchim -> count(); i++)
	{
		CCSprite* pausechim = (CCSprite*)_arrchim -> objectAtIndex(i);
		pausechim -> pauseSchedulerAndActions();
	}
	for(int i= 0; i < _arrnvtieuphai->count(); i++) 
	{
		CCSprite *resumenvtieuphai = (CCSprite*) _arrnvtieuphai->objectAtIndex(i);
		CCArray* _arrbomphai = resumenvtieuphai -> getChildren();
		for(int j= 0; j < _arrbomphai ->count(); j++)
		{
		CCSprite* resumebomphai = (CCSprite*) _arrbomphai ->objectAtIndex(j);
		resumebomphai -> pauseSchedulerAndActions();
		}
	}
	for(int i= 0; i < _arrnvtieutrai->count(); i++) 
	{
		CCSprite *resumenvtieutrai = (CCSprite*) _arrnvtieutrai->objectAtIndex(i);
		CCArray* _arrbomtrai = resumenvtieutrai -> getChildren();
		for(int j= 0; j < _arrbomtrai ->count(); j++)
		{
		CCSprite* resumebomtrai = (CCSprite*) _arrbomtrai ->objectAtIndex(j);
		resumebomtrai -> pauseSchedulerAndActions();
		}
	}
	for(int i= 0; i < _arrdayphai->count(); i++) 
	{
		CCSprite *resumedayphai = (CCSprite*) _arrdayphai->objectAtIndex(i);
		CCArray* _arrsocphai = resumedayphai -> getChildren();
		for(int j= 0; j < _arrsocphai ->count(); j++)
		{
		CCSprite* resumesocphai = (CCSprite*) _arrsocphai ->objectAtIndex(j);
		resumesocphai -> pauseSchedulerAndActions();
		}
	}
	for(int i= 0; i < _arrdaytrai->count(); i++) 
	{
		CCSprite *resumedaytrai = (CCSprite*) _arrdaytrai->objectAtIndex(i);
		CCArray* _arrsoctrai = resumedaytrai -> getChildren();
		for(int j= 0; j < _arrsoctrai ->count(); j++)
		{
		CCSprite* resumesoctrai = (CCSprite*) _arrsoctrai ->objectAtIndex(j);
		resumesoctrai -> pauseSchedulerAndActions();
		}
	}
	pause = CCSprite::create("pause_menu.png");
	pause -> setPosition(ccp(s.width/2, - pause -> getContentSize().height*4));
	this -> addChild(pause,4);
	CCScaleTo* scale = CCScaleTo::create(0, 4,4);
	pause -> runAction(scale);
	CCActionInterval* actpause = CCMoveTo::create(0.8,ccp(s.width/2, pause -> getContentSize().height*2));
	pause -> runAction(actpause);

	CCMenuItemImage* pquit = CCMenuItemImage::create("continue_button.png",0,
												this, menu_selector(HelloWorld::resetgame));
		pquit->setPosition(ccp(91,132));
		CCScaleTo* scale1 = CCScaleTo::create(0,0.6,0.6);
		pquit -> runAction(scale1);
		CCMenu* pMenu1 = CCMenu::create(pquit, NULL);
		pMenu1->setPosition(CCPointZero);
		pause ->addChild(pMenu1, 5);
	
}

void HelloWorld::resetgame(CCObject* pSender)
{
	this -> schedule(schedule_selector(HelloWorld::update));
	this -> schedule(schedule_selector(HelloWorld::gameplay));
	this -> schedule(schedule_selector(HelloWorld::calllich));
	this -> removeChild(pause);
	for(int i = 0; i < _arrquai -> count(); i++)
	{
		CCSprite* playquai = (CCSprite*)_arrquai -> objectAtIndex(i);
		playquai -> resumeSchedulerAndActions();
	}
	for(int i = 0; i < _arrnhanvat -> count(); i++)
	{
		CCSprite* playnhanvat = (CCSprite*)_arrnhanvat -> objectAtIndex(i);
		playnhanvat -> resumeSchedulerAndActions();
	}
	for(int i = 0; i < _arrchim -> count(); i++)
	{
		CCSprite* playchim = (CCSprite*)_arrchim -> objectAtIndex(i);
		playchim -> resumeSchedulerAndActions();
	}
	for(int i= 0; i < _arrnvtieuphai->count(); i++) 
	{
		CCSprite *resumenvtieuphai = (CCSprite*) _arrnvtieuphai->objectAtIndex(i);
		CCArray* _arrbomphai = resumenvtieuphai -> getChildren();
		for(int j= 0; j < _arrbomphai ->count(); j++)
		{
		CCSprite* resumebomphai = (CCSprite*) _arrbomphai ->objectAtIndex(j);
		resumebomphai -> resumeSchedulerAndActions();
		}
	}
	for(int i= 0; i < _arrnvtieutrai->count(); i++) 
	{
		CCSprite *resumenvtieutrai = (CCSprite*) _arrnvtieutrai->objectAtIndex(i);
		CCArray* _arrbomtrai = resumenvtieutrai -> getChildren();
		for(int j= 0; j < _arrbomtrai ->count(); j++)
		{
		CCSprite* resumebomtrai = (CCSprite*) _arrbomtrai ->objectAtIndex(j);
		resumebomtrai -> resumeSchedulerAndActions();
		}
	}
	for(int i= 0; i < _arrdayphai->count(); i++) 
	{
		CCSprite *resumedayphai = (CCSprite*) _arrdayphai->objectAtIndex(i);
		CCArray* _arrsocphai = resumedayphai -> getChildren();
		for(int j= 0; j < _arrsocphai ->count(); j++)
		{
		CCSprite* resumesocphai = (CCSprite*) _arrsocphai ->objectAtIndex(j);
		resumesocphai -> resumeSchedulerAndActions();
		}
	}
	for(int i= 0; i < _arrdaytrai->count(); i++) 
	{
		CCSprite *resumedaytrai = (CCSprite*) _arrdaytrai->objectAtIndex(i);
		CCArray* _arrsoctrai = resumedaytrai -> getChildren();
		for(int j= 0; j < _arrsoctrai ->count(); j++)
		{
		CCSprite* resumesoctrai = (CCSprite*) _arrsoctrai ->objectAtIndex(j);
		resumesoctrai -> resumeSchedulerAndActions();
		}
	}
}

void HelloWorld::menuCloseCallback(CCObject* pSender)
{
#if (CC_TARGET_PLATFORM == CC_PLATFORM_WINRT) || (CC_TARGET_PLATFORM == CC_PLATFORM_WP8)
	CCMessageBox("You pressed the close button. Windows Store Apps do not implement a close button.","Alert");
#else
	CCDirector::sharedDirector()->end();
#if (CC_TARGET_PLATFORM == CC_PLATFORM_IOS)
	exit(0);
#endif
#endif
}

//http://gamedev.stackexchange.com/questions/25513/how-to-play-animations-in-cocos2d-x
//http://harilogic.wordpress.com/2014/04/23/different-actions-available-in-cocos2dx-with-examples/
//http://vietgamedev.net/blog/1065/cocos2d-c%C3%A1i-qu%C3%A1i-g%C3%AC-trong-plist-file-khi-d%C3%B9ng-cho-sprite-v%C3%A0-animation-ph%E1%BA%A7n-/